package servicios;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.UriInfo;

import ApplicationLogic.controllers.SearchController;

@Path("/search")
public class SEARCHServiceFacade extends AbstractService
{
	@GET
	@Produces(MediaType.TEXT_XML)
	public String SearchWithCriteria(@Context UriInfo allUri ) throws Exception 
	{ 
	    MultivaluedMap<String, String> mpAllQueParams = allUri.getQueryParameters(); 
	    	    
	    SearchController SC = new SearchController();
	    try 
	    {
	    	String returnedModels = SC.SearchForModelByURI(mpAllQueParams);
			if (returnedModels == "") throw new WebApplicationException();
			return returnedModels;
	    } 
	    catch (Exception e) 
	    {
	    	throw(e);
	    	//ReturnException(e.getMessage());
	    	
		}
	
	    //return "";
	} 

	@GET
	@Produces(MediaType.TEXT_XML)
	@Path("getmodelsnames")
	public String SearchAllModelNames()
	{
		 SearchController SC = new SearchController();
		 String Names = "";
		 try
		 {
			 Names = SC.SearchForAllModelNames();
			 return Names;
		 }
		 catch(Exception e)
		 {
			 throw new WebApplicationException(e);
		 }
	
	}
	
	@GET
	@Produces(MediaType.TEXT_XML)
	@Path("getemptymodel")
	public String SearchEmptyModel(@QueryParam("model") String model)
	{
		
		try
		{
		SearchController SC = new SearchController();
		String SerializedEmptyModel = SC.SearchForAnEmptyModel(model);
		
		return SerializedEmptyModel;
		}
		catch(Exception e)
		{
			 throw new WebApplicationException(e);
		}
	}


}
